//
//  VoiceTabbar.m
//  VoiceShow
//
//  Created by luckyncl on 17/1/6.
//  Copyright © 2017年 luckyncl. All rights reserved.
//

#import "VoiceTabbar.h"
#import <UIView+YYAdd.h>
#import <UIImage+YYAdd.h>
@interface VoiceTabbar ()

@property (nonatomic , strong) UIButton *centerBtn;

@end




@implementation VoiceTabbar

/**
 *   设置tabbar的背景颜色
 */
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
       

        [self setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]]];
        //
        [self setShadowImage:[UIImage new]];
        
        UIButton *centerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [centerBtn setBackgroundColor:[UIColor whiteColor]];
        
        CGFloat width = 70;
        
        centerBtn.size = CGSizeMake(width, width);
        [centerBtn.layer setCornerRadius:width/2];
        centerBtn.clipsToBounds = YES;
        
        [centerBtn setImage:[UIImage imageNamed:@"加号"] forState:UIControlStateNormal];
        

        // 监听按钮点击
        [centerBtn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
        
        
        [self addSubview:centerBtn];
        
        self.centerBtn = centerBtn;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat width = self.width;
    CGFloat height = self.height;
    
    // 设置客服电话按钮
    self.centerBtn.center = CGPointMake(width / 2, height / 3);
    
    CGFloat buttonY = 0;
    CGFloat buttonW = width / 5;
    CGFloat buttonH = height;
    NSInteger index = 0;
    
    for (UIView *button  in self.subviews)
    {
        if (![button isKindOfClass:[UIControl class]] || button == self.centerBtn)
        {
            continue;
        }
        CGFloat buttonX = buttonW * ((index > 1)?(index + 1):index);
        button.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
        index++;
    }
    
}


//
- (void)buttonClick
{
  
    
    
}

@end
